package com.bdyc.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdyc.controller.custom.MapVo;
import com.bdyc.controller.custom.MyPo;
import com.bdyc.controller.custom.OrderGroup;
import com.bdyc.controller.custom.OrderInfoPo;
import com.bdyc.service.spring.OrderInfoService;
import com.bdyc.util.AppConstant;

@Controller
@RequestMapping("/orderInfo")
public class OrderInfoController {
	@Autowired(required=true)
	@Qualifier("orderInfoService")
	private OrderInfoService orderInfoServiceImpl;
	
	@RequestMapping(value="/findOrderInfoList.action",method=RequestMethod.POST)
	@ResponseBody//返回json数据注解
	public Map<String,Object> findOrderInfoList(MyPo po){
		Map<String,Object> map = new HashMap<String,Object>();
		//封装分页查询map
			//封装分页查询总记录数map 
			Map<String,Object> sendMap = MapVo.getSendMap(po);
			Integer rows = (Integer)sendMap.get("rows");
			try{
				List<OrderInfoPo> infoList = orderInfoServiceImpl.findOrderInfoList(sendMap);
				Integer count = orderInfoServiceImpl.findOrderInfoListCount(sendMap);
				Integer index = count/rows;
				Integer sum = count%rows==0?index:index +1;
				map.put("sum", sum);
				map.put("count", count);
				map.put("info", infoList);
				map.put(AppConstant.ISSUCC,AppConstant.SUCCESS);
				map.put(AppConstant.MSG,AppConstant.FINDSUCCESS);
				return map;
			}catch(Exception e){
				e.printStackTrace();
				map.put(AppConstant.ISSUCC,AppConstant.FALL);
				map.put(AppConstant.MSG,AppConstant.FINDFALL );
				return map;
			}
	}
	//根据flag分组查询
	@RequestMapping(value="/groupFlag.action",method=RequestMethod.POST)
	@ResponseBody//返回json数据注解
	public Map<String,Object> groupFlag(){
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			List<OrderGroup> flagList = orderInfoServiceImpl.groupFlag();
			map.put("flagList", flagList);
			map.put(AppConstant.ISSUCC,AppConstant.SUCCESS);
			map.put(AppConstant.MSG,AppConstant.FINDSUCCESS);
			return map;
		}catch(Exception e){
			e.printStackTrace();
			map.put(AppConstant.ISSUCC,AppConstant.SUCCESS);
			map.put(AppConstant.MSG,AppConstant.FINDSUCCESS);
			return map;
		}
	}
	//获取status分组查询 flag具体参数
	@RequestMapping(value="/groupStatus.action",method=RequestMethod.POST)
	@ResponseBody//返回json数据注解
	public Map<String,Object> groupStatus(Integer flag){
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			List<OrderGroup> statusList = orderInfoServiceImpl.groupStatus(flag);
			map.put("statusList", statusList);
			map.put(AppConstant.ISSUCC,AppConstant.SUCCESS);
			map.put(AppConstant.MSG,AppConstant.FINDSUCCESS);
			return map;
		}catch(Exception e){
			e.printStackTrace();
			map.put(AppConstant.ISSUCC,AppConstant.SUCCESS);
			map.put(AppConstant.MSG,AppConstant.FINDSUCCESS);
			return map;
		}
	}
	
	
}
